package ynu.lcy.elememicroservicecommon.utils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import ynu.lcy.elememicroservicecommon.exception.BusinessException;

import javax.servlet.http.HttpServletRequest;

@Component
public class TokenUtils {
    /**
     * 获取Token
     * */
    public static String getToken(HttpServletRequest request){
        //获取token
        String token = request.getHeader("token");
        if (StringUtils.isEmpty(token)) {
            token = request.getParameter("token");
        }
        if (StringUtils.isEmpty(token)){
            throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
        }
        return token;
    }


}
